﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using AR.Web.Services;
using AR.Entities;

namespace AR.Views.EntretienOrale.PerimetreEntretien
{
    public partial class ResultatGDC_SI_MSSKILLS : Page{
            public ResultatGDC_SI_MSSKILLS()
        {
            InitializeComponent();
        }


        public static void Resultats(int num , RadioButton radioName, RadioButton radioName2, RadioButton radioName3, RadioButton radioName4)
        {
           if(num == 3)
           { radioName.IsChecked = true; }
           else if (num == 2)
           { radioName2.IsChecked = true; }
           else if (num == 1)
           { radioName3.IsChecked = true; }
           else if( num == 0)
           { radioName4.IsChecked = true; }
           }

     

        // S'exécute lorsque l'utilisateur navigue vers cette page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            List<RadioButton> group = this.Descendents().OfType<RadioButton>().ToList();
           
            CandidatContext CandidatContext = new CandidatContext();
            EntretienOraleContext EntretienContext = new EntretienOraleContext();
            string sid = NavigationContext.QueryString["id"];
            int id = int.Parse(sid);
            var query = CandidatContext.GetCandidatByIDQuery(int.Parse(sid));
            CandidatContext.Load(query).Completed += (sender, ev) =>
            {
             CANDIDAT candidat = CandidatContext.CANDIDATs.SingleOrDefault();
             titreEntretien.Content = candidat.NOM + " " + candidat.PRENOM + " , Practice : " + candidat.PRACTICE.PRACTICE1;
             gcmTxt.Text = candidat.GCM_ESTIMEE_SM.ToString().Substring(0,1);
             candidatOK.IsChecked = true;
             if (candidat.ID_STATUT == 3)
                 candidatKO.IsChecked = true;
            };

            ENTRETIEN_ORALE entretien = new ENTRETIEN_ORALE();
            ENT_ORALE_CRITERE critere = new ENT_ORALE_CRITERE();

            var query2 = EntretienContext.GetEntretienByCandidatIDQuery(id);
           
            EntretienContext.Load(query2).Completed += (sender, ev) =>
               {
                   entretien = EntretienContext.ENTRETIEN_ORALEs.SingleOrDefault();
                   appreciationTxt.Text = entretien.APPRECIATION;
                   noteFinaleTxt.Text = entretien.NOTE.ToString();

                   int idCandidat = int.Parse(entretien.ID_ENT_OR.ToString());
                   var query3 = EntretienContext.FindEntretienOralCriteresByEntretienOralIdQuery(idCandidat);
                   EntretienContext.Load(query3).Completed += (sender2, ev2)
                       =>
                   { List<ENT_ORALE_CRITERE> EntretienOralCritereCollec = EntretienContext.ENT_ORALE_CRITEREs.ToList();
                  // var candidatquery = CandidatContext.GetCandidatByIDQuery(idCandidat);
                       
                       
                       #region Radio choices
                   if (EntretienOralCritereCollec.ElementAt(0).NOTE == "3")
                       A11.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(0).NOTE == "2")
                       A12.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(0).NOTE == "1")
                       A13.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(0).NOTE == "0")
                       A14.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(0).REMARQUE))
                       A1Rem.Text = EntretienOralCritereCollec.ElementAt(0).REMARQUE;
                   else
                   {
                       A1Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lA1Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }


                   if (EntretienOralCritereCollec.ElementAt(1).NOTE == "3")
                       A21.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(1).NOTE == "2")
                       A22.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(1).NOTE == "1")
                       A23.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(1).NOTE == "0")
                       A24.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(1).REMARQUE))
                       A2Rem.Text = EntretienOralCritereCollec.ElementAt(1).REMARQUE;
                   else
                   {
                       A2Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lA2Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(2).NOTE == "3")
                       A31.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(2).NOTE == "2")
                       A32.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(2).NOTE == "1")
                       A33.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(2).NOTE == "0")
                       A34.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(2).REMARQUE))
                       A3Rem.Text = EntretienOralCritereCollec.ElementAt(2).REMARQUE;
                   else
                   {
                       A3Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lA3Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(3).NOTE == "3")
                       B11.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(3).NOTE == "2")
                       B12.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(3).NOTE == "1")
                       B13.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(3).NOTE == "0")
                       B14.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(3).REMARQUE))
                       B1Rem.Text = EntretienOralCritereCollec.ElementAt(3).REMARQUE;
                   else
                   {
                       B1Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lB1Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(4).NOTE == "3")
                       B21.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(4).NOTE == "2")
                       B22.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(4).NOTE == "1")
                       B23.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(4).NOTE == "0")
                       B24.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(4).REMARQUE))
                       B2Rem.Text = EntretienOralCritereCollec.ElementAt(4).REMARQUE;
                   else
                   {
                       B2Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lB2Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(5).NOTE == "3")
                       B31.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(5).NOTE == "2")
                       B32.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(5).NOTE == "1")
                       B33.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(5).NOTE == "0")
                       B34.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(5).REMARQUE))
                       B3Rem.Text = EntretienOralCritereCollec.ElementAt(5).REMARQUE;
                   else
                   {
                       B3Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lB3Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(6).NOTE == "3")
                       B41.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(6).NOTE == "2")
                       B42.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(6).NOTE == "1")
                       B43.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(6).NOTE == "0")
                       B44.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(6).REMARQUE))
                       B4Rem.Text = EntretienOralCritereCollec.ElementAt(6).REMARQUE;
                   else
                   {
                       B4Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lB4Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(7).NOTE == "3")
                       B51.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(7).NOTE == "2")
                       B52.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(7).NOTE == "1")
                       B53.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(7).NOTE == "0")
                       B54.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(7).REMARQUE))
                       B5Rem.Text = EntretienOralCritereCollec.ElementAt(7).REMARQUE;
                   else
                   {
                       B5Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lB5Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(8).NOTE == "3")
                       C11.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(8).NOTE == "2")
                       C12.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(8).NOTE == "1")
                       C13.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(8).NOTE == "0")
                       C14.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(8).REMARQUE))
                       C1Rem.Text = EntretienOralCritereCollec.ElementAt(8).REMARQUE;
                   else
                   {
                       C1Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lC1Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }


                   if (EntretienOralCritereCollec.ElementAt(9).NOTE == "3")
                       C21.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(9).NOTE == "2")
                       C22.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(9).NOTE == "1")
                       C23.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(9).NOTE == "0")
                       C24.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(9).REMARQUE))
                       C2Rem.Text = EntretienOralCritereCollec.ElementAt(9).REMARQUE;
                   else
                   {
                       C2Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lC2Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(10).NOTE == "3")
                       C31.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(10).NOTE == "2")
                       C32.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(10).NOTE == "1")
                       C33.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(10).NOTE == "0")
                       C34.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(10).REMARQUE))
                       C3Rem.Text = EntretienOralCritereCollec.ElementAt(10).REMARQUE;
                   else
                   {
                       C3Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lC3Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }

                   if (EntretienOralCritereCollec.ElementAt(11).NOTE == "3")
                       C41.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(11).NOTE == "2")
                       C42.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(11).NOTE == "1")
                       C43.IsChecked = true;
                   else if (EntretienOralCritereCollec.ElementAt(11).NOTE == "0")
                       C44.IsChecked = true;
                   if (!string.IsNullOrEmpty(EntretienOralCritereCollec.ElementAt(11).REMARQUE))
                       C4Rem.Text = EntretienOralCritereCollec.ElementAt(11).REMARQUE;
                   else
                   {
                       C4Rem.Visibility = System.Windows.Visibility.Collapsed;
                       lC4Rem.Visibility = System.Windows.Visibility.Collapsed;
                   }
                 
                       #endregion

                   };

                  



               };


          


        }

        private void btnSend_Click(object sender, RoutedEventArgs e)
        {

        }

    }


   
    }

